package com.longrise.android.byjk.plugins.login;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;

import com.longrise.android.byjk.R;
import com.longrise.common.base.BaseActivity;
import com.longrise.common.utils.ActivityUtil;
import com.longrise.common.utils.AppUtil;

/**
 * Created by callxkj on 2016/12/16.
 * 支付密码为888888的进这个页面,安全提示
 * 1.2.4版本可以从引导页,登录也,启动页进入
 */

public class SafetyTipsActivity extends BaseActivity implements View.OnClickListener {

    private Button mBtmodify;
    private Toolbar mToolbar;
    public static String COME_PAGE = "come_page";
    public static final String LOGIN_ELSE = "login_else";
    public static final String LOGIN = "login";
    public static final String LOGIN_BYPHONE = "login_byphone";
    private String mComepage = LOGIN_ELSE;

    @Override
    public int getContentViewId(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_safety_tips;
    }

    @Override
    public void initView() {
        mToolbar = (Toolbar) findViewById(R.id.byjk_toolbar);
        mToolbar.setTitle(AppUtil.getString(R.string.aqts));
        setSupportActionBar(mToolbar);
        mBtmodify = (Button) findViewById(R.id.safety_bt);
        initData();
        initEvent();

    }

    private void initData() {
        Intent intent = getIntent();
        mComepage = intent.getStringExtra(COME_PAGE);
    }

    private void initEvent() {
        mBtmodify.setOnClickListener(this);
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                toLogin();
            }
        });
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            toLogin();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.safety_bt:
                startActivity(ChangePasswordActivity.class);
                break;
        }
    }

    /**
     * 点击返回去登录页
     */
    public void toLogin() {
        if (LOGIN_ELSE.equals(mComepage)) {
            ActivityUtil.removeActivity(this);
            ActivityUtil.finishAllAcivity();
            Intent loginIntent = new Intent(SafetyTipsActivity.this, LoginActivity.class);
            startActivity(loginIntent);
            finish();
        } else {
            finish();
        }
    }
}
